package com.aaa.controller;

import com.aaa.entity.Shop;
import com.aaa.service.ShopService;
import com.aaa.util.DefaultMsg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/shop")

public class ShopController {

    @Autowired
    private ShopService shopService;


    @RequestMapping("/listAll")
    public List<Shop> listAll(){
        List<Shop> list = shopService.list();
        return list;
    }

    @RequestMapping("/saveOrUpdate")
    public DefaultMsg saveOrUpdate(Shop shop){
        DefaultMsg defaultMsg = new DefaultMsg();
        boolean b = shopService.saveOrUpdate(shop);
        if (!b){
            defaultMsg.setSuccess(0);
            defaultMsg.setError("操作失败");
        }
        return defaultMsg;
    }

    @RequestMapping("/delete")
    public boolean delete(Shop shop){
        boolean save = shopService.removeById(shop.getSid());
        return save;
    }
}
